<template>
	<view class="page" :style="{minHeight:$height()}">
		<view class="header">
			<view class="headerTitle">
				余额
			</view>
			<view class="eDu">
				<text class="eDuIocn">￥</text> <text class="eDuNum">{{userinfo.money}}</text>
			</view>

			<view class="submit" @click="$next(`/pages/withDrawal/index`)">
				提现
			</view>
			
		</view>
		<view class="footer">
			<view class="footerHeader">
				<view class="footerHeaderLift">
					余额明细
				</view>
				<view class="submit1" style="display: flex;">
					是否开票: <u-switch style="margin-left: 10rpx;" v-model="isSwitch" activeColor="#3975EA"
						inactiveColor="rgb(230, 230, 230)" asyncChange @change="asyncChange"></u-switch>
				</view>
			</view>
			<view class="footerItem" v-for="(item,index) in list" :key="index">
				<view class="footerItemLeft">
					<view class="li">
						金额：￥ {{item.income}}
					</view>
					<view class="li date">
						{{item.date}}
					</view>
				</view>
				<view class="footerItemRight">
					<view class="tiXianChengGong">
						{{typeTextArr[item.type-1]}}
					</view>
					<view v-if="item.type == 1" style="margin-top:20rpx;">
						<u-button size="mini" type="error" @click="$next(`/pages/commissionCenters/commissionDetail?importId=${item.sourceId}`)">查看明细</u-button>
					</view>
				</view>
			</view>

		</view>
		<!-- 加载更多 -->
		<u-loadmore v-if="list.length !== 0" :status="status" :load-text="loadText" />
		<image v-else src="@/static/image/empty.png" mode="widthFix" class="is-empty"></image>

		<u-modal v-model="showModal" title="请输入开票点数"  @confirm="updateUser">
			<view class="slot-content" style="width:90%;margin:20px 5%;" >
				<u-input v-model="number" type="number" placeholder="输入3个点或6个点" :border="true" :customStyle="{width:'80%'}" />
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {},
				// 页面数据初始化状态
				loadText: {
					loadmore: '轻轻上拉，加载更多',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				isSwitch: true,
				typeTextArr: ["实际收益", "预发佣金", "提现", "提现冲正"],
				more: false,
				page: 1, //页码
				limit: 10, //条数
				list: [],
				showModal: false,
				number:''

			}

		},
		onLoad() {
			this.getMyCommissionRes()
		},
		onShow() {
			this.getUser()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.getMyCommissionRes()
		},
		//上拉加载
		onReachBottom() {
			if (this.page == 1) {
				return
			}
			if (this.more) {

				this.getMyCommissionRes()
			}
		},
		methods: {
			getMyCommissionRes() {
				this.$axios.request(this.$api.getMyCommissionRes, "GET", {
					page: this.page,
					limit: 10,
					type: '1',
					orderField: 'id',
					order: 'desc'
				}).then((val) => {

					uni.stopPullDownRefresh();
					this.list = this.page == 1 ? val.data.list : this.list.concat(val.data.list)
					if (Math.ceil(val.data.total / this.limit) > this.page) {
						this.more = true;
						this.page++
					} else {
						this.more = false;
					}
				})
			},
			asyncChange(e) {
				uni.showModal({
					content: e ? '确定要开票吗？' : '确定不需要开票吗？',
					success: (res) => {
						if (res.confirm) {
							this.isSwitch = e
							if(e){
								this.showModal = true
							}else{
								this.updateUser()
							}
							
						} else {
							this.isSwitch = !e
						}
					}
				})
			},
			updateUser(){
				
				if(this.isSwitch){
					if(this.number != 3 &&	 this.number != 6){
						this.$msg.toast("请输入3或者6！")
						this.showModal = true
						return
					}
					
				}
				var params = {
					invoice: this.isSwitch ? 1 : 0,
					tax: this.isSwitch ? this.number : 0
				}
			
				this.$axios.request(this.$api.updateUser, "POST", params).then((val) => {
					this.showModal = false
					this.getUser()
				})
			},
			getUser() {
				this.$axios.request(this.$api.getUser, "GET").then((val) => {
					this.userinfo = val.data
					this.isSwitch = val.data.invoice == 0 ? false : true
				})
			},

		}
	}
</script>

<style>
	.page {
		width: 100%;
		background-color: #F3F4F8;
		overflow-y: hidden;
	}

	.header {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 750rpx;
		height: 388rpx;
		background-color: #3975EA;
	}

	.headerTitle {
		font-size: 20rpx;
		
		font-weight: 300;
		color: #FFFFFF;
	}

	.eDu {

		margin: 12rpx 0 18rpx;
	}

	.leiBox {
		display: flex;
		justify-content: center;
		font-size: 20rpx;
		
		font-weight: 300;
		color: #FFFFFF;
	}

	.leiBoxItem {
		margin: 0 10rpx;
	}

	.submit {
		padding: 4rpx 30rpx;
		border: 1rpx solid #3975EA;
		border-radius: 4rpx;
		font-size: 28rpx;
		
		font-weight: 400;
		line-height: 64rpx;
		text-align: center;
		color: #3975EA;
		background-color: #fff;
		margin: 20rpx 0 20rpx;
	}

	.submit1 {
		border-radius: 4rpx;
		font-size: 28rpx;
		
		font-weight: 400;
		line-height: 64rpx;
		text-align: center;
		color: #3975EA;
		background-color: #fff;
		margin: 20rpx 0 20rpx;
	}

	.embodyManagement {
		font-size: 28rpx;
		
		font-weight: 400;
		color: #FFFFFF
	}

	.eDuNum {
		font-size: 36rpx;
		
		font-weight: 600;
		color: #FFFFFF;
	}

	.eDuIocn {
		font-size: 13px !important;
		margin-right: 10rpx;
		
		font-weight: 600;
		color: #FFFFFF;
	}

	.footer {
		width: 100%;
		/* height: 836rpx; */
		background-color: #fff;
		margin-top: 12rpx;
		/* background-color: #3975EA; */
	}

	.footerHeader {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 702rpx;
		padding: 0 8rpx;
		margin: 0 auto 0;
		height: 96rpx;
		border-bottom: 1rpx solid #F1F1F1;
	}

	.footerHeaderLift {
		font-size: 28rpx;
		font-family: 'PingFang SC';
		font-weight: 600;
		color: #333333;
	}

	.footerTxt {
		font-size: 24rpx;
		font-family: 'PingFang SC';
		font-weight: 600;
		color: #3975EA;
		margin-right: 12rpx;
	}

	.footerItem {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 702rpx;
		height: 142rpx;
		border-bottom: 1rpx solid #F1F1F1;
		border-radius: 4rpx;
		margin: 0 auto 0;
	}

	.footerItemLeft,
	.footerItemRight {
		display: flex;
		justify-content: center;
		align-items: flex-start;
		flex-direction: column;
		height: 100%;
	}

	.footerItemRight {
		align-items: center;
	}

	.li {
		font-size: 24rpx;
		font-family: 'PingFang SC';
		font-weight: 300;
		color: #333333;
		margin: 3rpx;
	}

	.date {
		font-size: 20rpx;
		font-family: .PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 16rpx;
	}

	.genjin {
		font-size: 24rpx;
		
		font-weight: 400;
		color: #FFA12A;
	}

	.tiXianChengGong {
		font-size: 24Rpx;
		
		font-weight: 400;
		/* line-height: 46px; */
		color: #3975EA;
	}

	.tiXianShiBai {
		font-size: 24rpx;
		
		font-weight: 400;
		color: #FF2D55;

	}

	.lookYuanYin {
		font-size: 20rpx;
		
		font-weight: 300;
		color: #666666;
		margin-top: 8rpx;
	}

	.daoZhang {
		font-size: 24rpx;
		font-family: 'PingFang SC';
		font-weight: 400;
		color: #6FC954;
	}
</style>
